package net.pimpas.validation.operation;

import net.pimpas.operation.exception.OperationException;
import net.pimpas.operation.operation.OperationAbstract;
import net.pimpas.validation.result.ValidationResult;

public abstract class AbstractValidationOperation extends OperationAbstract<Object> implements ValidationOperation<Object> {

	private ValidationResult result;
	private Object[] parameters;

	@Override
	public final void init(Object... arg0) throws OperationException {
		this.setResult((ValidationResult) arg0[0]);
		this.setParameters(new Object[arg0.length-1]);
		int i = 0;
		for(Object obj: arg0) {
			if(i==0) { i++; continue; }
			this.getParameters()[i-1] = obj;
		}
	}
	
	@Override
	public abstract Object call() throws Exception;
	
	public ValidationResult getResult() {
		return result;
	}

	public void setResult(ValidationResult result) {
		this.result = result;
	}

	protected Object[] getParameters() {
		return parameters;
	}

	private void setParameters(Object[] parameters) {
		this.parameters = parameters;
	}
}